package com.code.leetcode._202504;
/**35. 搜索插入位置 ，难度为 简单。**/
public class SearchLocation {

    public int searchInsert(int[] nums, int t) {
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == t || nums[i] > t) return i;
        }
        return nums.length;
    }

    public int searchInsert1(int[] nums, int t) {
        int n = nums.length;
        int l = 0, r = n - 1;
        while (l < r) {
            int mid = l + r >> 1;
            if (nums[mid] >= t) {
                r = mid;
            } else {
                l = mid + 1;
            }
        }
        return nums[r] >= t ? r : r + 1;
    }
}
